import db from "@/db";

export async function GET(request: Request, { params }: { params: { name: string } }) {

    return Response.json({
        code: 0,
        data: db.data.users,
        msg: 'success'
    })
}

export async function POST(request: Request) {
    const data = await request.json()
    if (db.data.users.findIndex(user => user.name === data.name) != -1) {
        return Response.json({
            code: 1,
            msg: '用户已存在!'
        })
    }
    await db.update(({ users }) => users.push({
        id: users.length + 1,
        ...data
    }))
    return Response.json({
        code: 0,
        msg: '保存成功!'
    })
}